package edu.ccut.saturn.component.impl;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import edu.ccut.saturn.component.IBundleDataInfo;
import edu.ccut.saturn.component.IDataInfo;
import edu.ccut.saturn.component.ILogger;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnLoggerManager;

public class SaturnBundleDataInfo implements IBundleDataInfo {

	private static final String LOGGER_KEY_LOAD_BUNDLE = SaturnLoggerManager.LOGGER_KEY_LOAD_BUNDLE;

	protected static ILogger logger = SaturnLoggerManager.getInstance()
			.getSaturnLogger(LOGGER_KEY_LOAD_BUNDLE);

	private String bundlesSymbolicName;

	private List<URL> dataUrl;

	private List<IDataInfo> dataInfos;

	public SaturnBundleDataInfo(String bundlesSymbolicName) {
		this.bundlesSymbolicName = bundlesSymbolicName;
		this.dataUrl = new ArrayList<URL>();
		this.dataInfos = new ArrayList<IDataInfo>();
	}

	public void addDateUrl(URL url) {
		this.dataUrl.add(url);
	}

	public String getBundleSymbolicName() {
		return this.bundlesSymbolicName;
	}

	public List<URL> getDateUrls() {
		return this.dataUrl;
	}

	public void addDataInfo(IDataInfo dataInfo) throws SaturnComponentException {

		for (IDataInfo info : dataInfos) {

			if (info.getDataFullKey().equals(dataInfo.getDataFullKey())) {
				logger
						.error("add data infomation failed, because the data key ["
								+ dataInfo.getDataFullKey()
								+ "] is already existed");

				throw new SaturnComponentException(
						"add data infomation failed, because the data key ["
								+ dataInfo.getDataFullKey()
								+ "] is already existed");
			}
		}
		this.dataInfos.add(dataInfo);
	}

	public List<IDataInfo> getDataInfos() {
		return this.dataInfos;
	}

	public void addDataInfos(List<IDataInfo> dataInfos) {
		this.dataInfos.addAll(dataInfos);
	}
}
